<template>
	<view class="set">
		<view class="set-wrapper">
			<view class="set-item" v-for="(item,index) in studyList" :key='index' @click="hanldStudyInfo(item)">
				<view class="set-title">
					<image src="/static/img/xuanz-ison1.png" style="width: 19px;height: 19px;padding: 0 12px; vertical-align: bottom;"></image>
					{{item.title}}</view>
				<image src='/static/img/right_icon.png'></image>
			</view>
		</view>
		
		<view v-if="loadAll&&studyList.length>=10" class="no-more-data">没有更多了</view>
		<view v-if="studyList.length == 0" class="no-more-data">
		  暂无数据
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				studyList:[],
				page:1,
				loadAll:false
			}
		},
		onShow(){
			this.getNews()
		},
		onPullDownRefresh() {
		  // console.log('下拉刷新')
		  this.loadAll = false;
		  this.studyList = [];
		  this.page = 1;
		  this.getNews();
		},
		onReachBottom() {
		  console.log('上拉加载')
		  if (!this.loadAll) {
		    this.getNews();
		  }
		},
		methods: {
			getNews(){
				this.$http.news({type:4}).then(res => {
					uni.stopPullDownRefresh()
					if(res.data){
						let _list = res.data.data
						let totalPage = res.data.last_page
						if (this.page > totalPage || _list.length == 0) {
						  this.loadAll = true
						  return
						}
						if(_list.length > 0){
						  this.studyList = this.studyList.concat(_list);
						}
						this.page++;
					}
				})
			},
			hanldStudyInfo(item){
				uni.navigateTo({
					url:'studyInfo?detail='+encodeURIComponent(JSON.stringify(item))
				})
			}
		}
	}
</script>

<style scoped>
.set{
	width: 100%;
	margin: 15px;
}
.set-wrapper{
}
.set-title{
	color: rgba(17, 17, 16, 1);
	font-weight: bold;
	font-size: 12px;
}
.set-item{
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	
	height:88upx;
	background:rgba(187,187,187,0.1);
	border-radius:10upx;
	margin: 10px 0;
}
.set-item image{
	width: 27px;
	height: 27px;
}
</style>
